package com.song.studylineserver.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.convert.Convert;
import com.song.studylineserver.service.MenuService;
import com.song.studylineserver.service.RoleService;
import com.song.studylineserver.util.Loggers;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Component("StpInterfaceImpl")
public class StpInterfaceImpl implements StpInterface {

    @Resource
    RoleService roleService;

    @Resource
    MenuService menuService;


    /**
     * 返回所有权限
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        List<String> list = new ArrayList<String>();
        list.addAll(menuService.selectMenuPermsByUserId(Convert.toLong(loginId) ));
        return list;
    }

    /**
     * 返回用户角色
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> list = new ArrayList<String>();
        list.addAll(roleService.selectRolePermissionByUserId(Convert.toLong(loginId)));
        return list;
    }
}
